package com.data.center.controller;

import com.data.center.dto.AdditionalInformationDto;
import com.data.center.dto.PersonDto;
import com.data.center.util.ExcelToListUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
@Slf4j
public class PersonControllerTestAC {

    @Autowired
    PersonController personController;

    // 常量尽可能用static final修饰，防止被修改
    // 这里改成相对路径的方式，就不用每次都要拉下来改了
    private static final String filePath1 = ".\\source\\Person\\Person测试用例.xlsx";
    private static final String filePath2 = ".\\source\\Person\\Person测试用例1.xlsx";
    private static final String filePath3 = ".\\source\\Person\\Person测试用例2.xlsx";
    private static final String filePath4 = ".\\source\\Person\\Person测试用例随机抽取.xlsx";
    private static final String additionalInformationPath = ".\\source\\Person\\增量信息.xlsx";

    @Test
    //执行时可能需修改PersonDto.java
    public void testFindPerson() {

        ExcelToListUtils<PersonDto> excelToListUtils = new ExcelToListUtils<>();
        List<PersonDto> personDtos = excelToListUtils.excelToList(filePath4, PersonDto.class);
        log.info("personDtos" + personDtos);
        //  F:\作业\毕业设计\persontest\data-center\source\Person\Person测试用例随机抽取.xlsx

        for (int i = 0; i <= 99; i++) {
            log.info("findPerson(personDtos.get(" + i + "))" + personController.findPerson(personDtos.get(i)));
            Assert.assertEquals(personController.findPerson(personDtos.get(i)).getCode(), "200");

            List<PersonDto> result = (List) personController.findPerson(personDtos.get(i)).getResult();
            Assert.assertEquals(result.size(), 2);
        }
    }



    @Test
    //执行时可能需修改PersonDto.java
    public void testAddPerson() {
            ExcelToListUtils<PersonDto> excelToListUtils = new ExcelToListUtils<>();
            List<PersonDto> personDtos = excelToListUtils.excelToList(filePath1, PersonDto.class);
            log.info("personDtos" + personDtos);
            //  F:\作业\毕业设计\persontest\data-center\source\Person\Person测试用例.xlsx
            for (int i = 0; i <= 99; i++) {
                log.info("addPerson(personDtos.get(" + i + "))" + personController.addPerson(personDtos.get(i)));
            }
        }

    @Test
    //执行时可能需修改PersonDto.java
    public void testForceAddPerson() {
        ExcelToListUtils<PersonDto> excelToListUtils = new ExcelToListUtils<>();
        List<PersonDto> personDtos = excelToListUtils.excelToList(filePath1, PersonDto.class);
        log.info("personDtos" + personDtos);
        //  F:\作业\毕业设计\persontest\data-center\source\Person\Person测试用例.xlsx
        for (int i = 0; i <= 99; i++) {
            log.info("forceAddPerson(personDtos.get(" + i + "))" + personController.forceAddPerson(personDtos.get(i)));
        }
    }

//    @Test
    //执行时可能需修改PersonDto.java
//    public void testUpdatePerson() {
//        ExcelToListUtils<PersonDto> excelToListUtils = new ExcelToListUtils<>();
//        List<PersonDto> personDtos = excelToListUtils.excelToList(filePath4, PersonDto.class);
//        log.info("personDtos" + personDtos);
//
//        for (int i = 0; i <= 99; i++) {
//            log.info("updatePerson(personDtos.get( + i + ))" + personController.updatePerson(personDtos.get(i)));
//        }
//    }

    @Test
    //执行时可能需修改PersonDto.java
    public void testLogicalDelete() {
        ExcelToListUtils<PersonDto> excelToListUtils = new ExcelToListUtils<>();
        List<PersonDto> personDtos = excelToListUtils.excelToList(filePath4, PersonDto.class);
        log.info("personDtos" + personDtos);

        for (int i = 0; i <= 99; i++) {
            log.info("logicalDelete(personDtos.get( + i + ))" + personController.logicalDelete(personDtos.get(i)));
            Assert.assertEquals(personController.logicalDelete(personDtos.get(i)).getCode(), "-1");
        }
    }

    @Test
    //执行时可能需修改PersonDto.java
    public void testPhysicalDelete() {
        ExcelToListUtils<PersonDto> excelToListUtils = new ExcelToListUtils<>();
        List<PersonDto> personDtos = excelToListUtils.excelToList(filePath4, PersonDto.class);
        log.info("personDtos" + personDtos);

        for (int i = 0; i <= 99; i++) {
            log.info("physicalDelete(personDtos.get( + i + ))" + personController.physicalDelete(personDtos.get(i)));
//            Assert.assertEquals(personController.physicalDelete(personDtos.get(i)).getCode(), "-1");
        }
    }

    @Test
    //执行时可能需修改PersonDto.java
    public void testMerge() {
        ExcelToListUtils<PersonDto> excelToListUtils1 = new ExcelToListUtils<>();
        List<PersonDto> personDtos1 = excelToListUtils1.excelToList(filePath2, PersonDto.class);
        log.info("personDtos1" + personDtos1);
        //  F:\作业\毕业设计\persontest\data-center\source\Person\Person测试用例1.xlsx
        ExcelToListUtils<PersonDto> excelToListUtils2 = new ExcelToListUtils<>();
        List<PersonDto> personDtos2 = excelToListUtils2.excelToList(filePath3, PersonDto.class);
        log.info("personDtos2" + personDtos2);
        //  F:\作业\毕业设计\persontest\data-center\source\Person\Person测试用例2.xlsx

        for (int i = 0; i <= 99; i++) {
            log.info("merge(personDtos1.get(i),personDtos2.get(i))" + personController.merge(personDtos1.get(i),personDtos2.get(i)));
//            Assert.assertEquals(personController.merge(personDtos1.get(i),personDtos2.get(i)).getCode(), "-1");
        }
    }
}
